package io.geekidea.boot;

public class Main {

    int fx = 1, fy = 3, n = 3, cnt;
    int[] dx = {0, 0, -1, -1, -1, 1, 1, 1};
    int[] dy = {1, -1, 1, 0, -1, 1, 0, -1};

    public static void main(String[] args) {
        new Main().start();
    }

    void dfs(int x, int y, int[][] maze) {
        if (x == fx && y == fy) {
            cnt++;
            System.out.println("----------------------");
            return;
        }
        maze[x][y] = 1;
        for (int i = 0; i < 8; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (nx >= 1 && nx <= n && ny >= 1 && ny <= n && maze[nx][ny] == 0) {
                System.out.println(nx + " " + ny);
                dfs(nx, ny, maze);
            }
        }
        maze[x][y] = 0;
    }


    public void start() {
        int[][] maze = new int[n + 1][n + 1];
        int sx = 1, sy = 1;
        maze[0] = new int[]{0, 0, 0, 0};
        maze[1] = new int[]{0, 0, 0, 0};
        maze[2] = new int[]{0, 0, 1, 1};
        maze[3] = new int[]{0, 1, 0, 0};
        dfs(sx, sy, maze);
        System.out.println(cnt);
    }
}
